// BlockchainTravelBackend/middleware/authMiddleware.js
const jwt = require('jsonwebtoken');
const secret = 'zhx19970931316mslerdt';

const verifyToken = (req, res, next) => {
  const token = req.headers.authorization && req.headers.authorization.split(' ')[1];
  if (!token) {
    return res.status(401).json({ message: '未授权，未提供 token' });
  }
  try {
    const decoded = jwt.verify(token, secret);
    req.user = decoded;
    next();
  } catch (error) {
    return res.status(403).json({ message: 'token 无效' });
  }
};

module.exports = verifyToken;




